home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V2 / 6.1 - MyStarter / CMouse.c < prev    next >
Text File  |  1991-08-24  |  3KB  |  135 lines

  1. /************************************************************/
  2. /*                                                            */
  3. /*    CMouse Code from Chapter Six of                            */
  4. /*                                                            */
  5. /*        *** The Macintosh Programming Primer ***            */
  6. /*                                                            */
  7. /*    Copyright 1990, Dave Mark                                */
  8. /*                                                            */
  9. /*    This program demonstrates specific Mac programming        */
  10. /*    techniques.                                                */
  11. /*                                                            */
  12. /************************************************************/
  13.  
  14. #include "CMouse.h"
  15.  
  16.  
  17. /******************************** IMouse *********/
  18.  
  19. void CMouse::IMouse( int    strID, int objWidth, int objHeight,
  20.                         Point hitPt, Rect theLoc, CPanorama *theRama )
  21. {
  22.     LongRect r;
  23.     
  24.     IMouseTask( strID );
  25.  
  26.     thePanorama = theRama;
  27.     theLocation = theLoc;    /* The current location of the gray rect. */
  28.     
  29.     /* We'll use theBounds to restrict the gray rect's movement, so the
  30.         DragPane will be restricted to the bounds of the panorama. */
  31.     
  32.     thePanorama->GetBounds(&r); 
  33.     r.left += hitPt.h;
  34.     r.top += hitPt.v;
  35.     r.right -= (objWidth - hitPt.h);
  36.     r.bottom -= (objHeight - hitPt.v);
  37.     /*theBounds = r;OLD*/
  38.     LongToQDRect( &r, &theBounds );
  39. }
  40.  
  41.  
  42. /******************************** BeginTracking *********/
  43.  
  44. void CMouse::BeginTracking( struct LongPt *startPt )
  45. {
  46.     Rect    r;
  47.     
  48.     PenMode( patXor );
  49.     PenPat( gray );
  50.     
  51.     r = theLocation;
  52.     FrameRect( &r );
  53. }
  54.  
  55.  
  56. /******************************** KeepTracking *********/
  57.  
  58. void CMouse::KeepTracking( struct LongPt *currPt, struct LongPt *prevPt,
  59.                                             struct LongPt *startPt )
  60. {
  61.     LongRect    r, f;
  62.     Rect        shortR;
  63.     long        curTicks;
  64.     LongPt        startPosit, newPosit, cp, pp;
  65.     RgnHandle    clipRgn;
  66.     
  67.     thePanorama->GetPosition( &startPosit );
  68.     
  69.     clipRgn = NewRgn();
  70.     
  71.     if ( thePanorama->AutoScroll( currPt )
  72.             || ! EqualLongPt( currPt, prevPt ) )
  73.     {
  74.         thePanorama->GetPosition( &newPosit );
  75.         
  76.         GetClip( clipRgn );
  77.         QDToLongRect( &((**clipRgn).rgnBBox), &r );
  78.         OffsetLongRect( &r, startPosit.h - newPosit.h,
  79.                 startPosit.v - newPosit.v );
  80.                 
  81.         thePanorama->GetFrame(&f);
  82.         PinInRect(&f, (LongPt *)(&(r.top)));
  83.         PinInRect(&f, (LongPt *)(&(r.bottom)));
  84.         
  85.         LongToQDRect( &r, &shortR );
  86.         ClipRect( &shortR );
  87.         
  88.         shortR = theLocation;    /* Erase old gray rect */
  89.         
  90.         curTicks = TickCount();
  91.         while ( curTicks == TickCount() ) ;
  92.         FrameRect( &shortR );
  93.         QDToLongRect( &shortR, &r );
  94.         
  95.         cp = *currPt;
  96.         pp = *prevPt;
  97.         QDToLongRect( &theBounds, &f );
  98.         PinInRect(&f, &cp);
  99.         PinInRect(&f, &pp);
  100.  
  101.         OffsetLongRect(&r, cp.h - pp.h, cp.v - pp.v);    
  102.             
  103.         SetClip( clipRgn );
  104.         
  105.         curTicks = TickCount();
  106.         while ( curTicks == TickCount() ) ;
  107.         
  108.         LongToQDRect( &r, &shortR );
  109.         FrameRect( &shortR );                /* Draw new gray rect */
  110.         theLocation = shortR;        /* update theLocation instance var */
  111.     }
  112.     
  113.     DisposeRgn( clipRgn );
  114. }
  115.  
  116.  
  117. /******************************** EndTracking *********/
  118.  
  119. void CMouse::EndTracking( struct LongPt  *currPt, struct LongPt  *prevPt,
  120.                                     struct LongPt  *startPt )
  121. {
  122.     Rect    r;
  123.     
  124.     r = theLocation;    
  125.     FrameRect( &r );
  126.     PenNormal();
  127. }
  128.  
  129.  
  130. /******************************** GetLocation *********/
  131.  
  132. void CMouse::GetLocation( Rect *theLoc )
  133. {
  134.     *theLoc = theLocation;
  135. }